﻿using System;
using Eisk.BusinessEntities;
using Eisk.BusinessLogicLayer;
using Eisk.Helpers;

namespace Eisk.Web
{
    public partial class view_supplier : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["supplierId"]))
                {
                    string supplierID = Request.QueryString["supplierId"];
                    int supplierId = Convert.ToInt16(supplierID);

                    try
                    {
                        Supplier newSupplier = new SupplierBLL().GetSupplierBySupplierId(supplierId);

                        if (newSupplier != null)
                        {
                            LiteralName.Text = newSupplier.Name;
                            LiteralAddress.Text = newSupplier.Address;
                            LiteralPhone.Text = newSupplier.Phone;
                            LiteralEmail.Text = newSupplier.Email;
                            LiteralZip.Text = newSupplier.Zip;
                        }
                    }
                    catch (Exception ex)
                    {
                        ltlMessage.Text += String.Format(MessageFormatter.GetFormattedErrorMessage("Suppliers not found for. Supplier Id {0}"), supplierId);
                        SupplierViewer.Visible = false;
                    }
                }
                else
                {
                    ltlMessage.Text += String.Format(MessageFormatter.GetFormattedErrorMessage("No Suppliers Id Provided"), 0);
                    SupplierViewer.Visible = false;
                }
            }

        }

        protected void LinkButtonAddSupplier_Click(object sender, System.EventArgs e)
        {
            Response.Redirect("add-supplier.aspx");
        }
        protected void LinkButtonViewSuppliers_Click(object sender, System.EventArgs e)
        {
            Response.Redirect("view-suppliers.aspx");
        }
        protected void LinkButtonEditSupplier_Click(object sender, System.EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["supplierId"]))
            {
                string supplierID = Request.QueryString["supplierId"];

                Response.Redirect("add-supplier.aspx?supplierId=" + supplierID);
            }
        }
    }
}
